package com.karl.mytask_2.activity;

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.karl.mytask_2.R;
import com.karl.mytask_2.fragment.HostFragment;
import com.karl.mytask_2.fragment.PublishFragment;
import com.karl.mytask_2.fragment.TaskFragment;
import com.karl.mytask_2.fragment.UserFragment;
import com.karl.mytask_2.tools.BaseActivity;
import com.karl.mytask_2.tools.BaseFragmentActivity;

public class MainActivity extends BaseFragmentActivity {
    private FragmentTabHost mTabHost = null;
    private View mIndicator = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        initTab();

    }
    private void initTab(){
        mTabHost = (FragmentTabHost) findViewById(R.id.myTab);
        mTabHost.setup(MainActivity.this, getSupportFragmentManager(), android.R.id.tabcontent);

        //添加Tab名称和图片
        mIndicator = getIndicatorView("主页",R.layout.tab_host);
        mTabHost.addTab(mTabHost.newTabSpec("01").setIndicator(mIndicator), HostFragment.class,null);

        mIndicator = getIndicatorView("已发布",R.layout.tab_publish);
        mTabHost.addTab(mTabHost.newTabSpec("02").setIndicator(mIndicator),PublishFragment.class,null);

        mIndicator = getIndicatorView("做任务",R.layout.tab_task);
        mTabHost.addTab(mTabHost.newTabSpec("03").setIndicator(mIndicator),TaskFragment.class,null);

        mIndicator = getIndicatorView("个人中心",R.layout.tab_user);
        mTabHost.addTab(mTabHost.newTabSpec("04").setIndicator(mIndicator),UserFragment.class,null);
    }

    private View getIndicatorView(String name,int layoutId){
        View mView = getLayoutInflater().inflate(layoutId,null);
        TextView mTxt = (TextView) mView.findViewById(R.id.tab_txt);
        mTxt.setText(name);
        return mView;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mTabHost = null;
    }
}
